/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.img;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

/**
 *
 * @author Lucas
 */
public class SalPimenta implements Filtro{

    @Override
    public String getName() {
        return "Sal e Pimenta";
    }

    @Override
    public Map<String, List> filtrar(String image) {
       System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat imgGray = Highgui.imread("./src/data/img/" + image, 0);
        
        int colunas = imgGray.cols();
        int linhas = imgGray.rows();
        
        /*
         * Sal e pimenta
         * Aplicação aleatoria de brancos e pretos no
         */
        int rand = ((colunas * linhas)/4);
        Random randoColuna = new Random();
        Random randoLinha = new Random();
        for (int l = 1; l < rand - 1; l++) {
            imgGray.put(randoLinha.nextInt(linhas), 
                    randoColuna.nextInt(colunas), 0.0);  
        }
  
        //Variaveis auxiliares
        double[] valorRGB;
        int a = 0;
        int valorArray;
        
        /*
         * pega os pixeis e salva num array list...
         */
        List<Integer> histGray = new ArrayList<>();
        for (int i = 0; i < 255; i++) {
            histGray.add(i, 0);
        }
        for (int i = 0; i < linhas; i++) {
            for (int j = 0; j < colunas; j++) {
                valorRGB = imgGray.get(i, j);
                a = (int) valorRGB[0];
                valorArray = histGray.get(a);
                valorArray += 1;
                histGray.set(a, valorArray);
                System.out.println(imgGray.get(i, j)[0]);
            }
        }
        
        Map<String, List> valores = new HashMap();
        valores.put("Sal e Pimenta", histGray);
        return valores;
    }
    
}
